﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLCOMSqlClient;
using System.Collections.ObjectModel;

namespace SilverlightSQLServer
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {

        }


        private void TestButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string connString = @"Data Source=.\sql2008;Initial Catalog=Rolodex;User ID=sa;Password=new5horizon7";

                var data = COMSqlDatabase.ExecuteQuery<User>(connString, "Select * From Users Where UserID<@userID", SLCOMSqlClient.CommandType.Text, new SqlParameter[] {
                    new SqlParameter("@userID", 3)
                });

                var data4 = COMSqlDatabase.ExecuteQuery<User2>(connString, "Select * From Users Where UserID<@userID", SLCOMSqlClient.CommandType.Text, new SqlParameter[] {
                    new SqlParameter("@userID", 3)
                });

                var data1 = COMSqlDatabase.ExecuteQuery<User>(connString, "Select * From Users Where UserID<=1", SLCOMSqlClient.CommandType.Text);

                var data5 = COMSqlDatabase.ExecuteScalar(connString, "Select Count(1) From Users Where UserID>=0", SLCOMSqlClient.CommandType.Text);

                var data6 = COMSqlDatabase.ExecuteScalar(connString, "Select Count(1) From Users Where UserID>=@userID", SLCOMSqlClient.CommandType.Text, new SqlParameter[] {
                    new SqlParameter("@userID", 0)
                });

                var data2 = COMSqlDatabase.ExecuteNonQuery(connString, "Update Users Set password=@password Where UserId=@userID", SLCOMSqlClient.CommandType.Text, new SqlParameter[] {
                    new SqlParameter("@password", Guid.NewGuid().ToString()),
                    new SqlParameter("@userID", 3)
                });

                var data3 = COMSqlDatabase.ExecuteNonQuery(connString, "Update Users Set password='' Where UserId=3", SLCOMSqlClient.CommandType.Text);
                MessageBox.Show("Test completed");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
    }
}
